/**
 * 计时器
 */
export class TimerDelay {
    private timer: number | undefined

    constructor(
        private delay: number,
        private callback: Function,
    ) {}

    start(): void {
        this.timer = setInterval(this.callback, this.delay)
    }

    reset(): void {
        this.stop()
        this.start()
    }

    stop(): void {
        if (this.timer) {
            clearInterval(this.timer)
            this.timer = undefined
        }
    }
}
